﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace RegexTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string text = tb1.Text.Trim();
            tb2.Text = IsValidIPv4(text) ? "Yes" : "No";
            int a = 0;
        }

        public static bool IsValidIPv4(string text)
        {
            Match m = Regex.Match(text, "^\\d+\\.\\d+\\.\\d+\\.\\d+$");
            if (m.Length == 0 || !m.Success)
                return false;
            foreach (string s in m.Value.Split('.'))
            {
                if (int.Parse(s) < 0 || int.Parse(s) > 255)
                    return false;
            }
            return true;
        }
    }
}
